﻿using System.ComponentModel;

namespace ReactiveChannelMessaging.WinForms;

/// <summary>
/// 命令项类，实现INotifyPropertyChanged接口
/// </summary>
public class CommandItem : INotifyPropertyChanged
{
    private bool _isSelected;
    private int _index;
    private string _functionCode = "";
    private string _device = "";
    private string _register = "";
    private string _value = "";
    private string _command = "";
    private string _description = "";
    private string _remark = "";

    public event PropertyChangedEventHandler? PropertyChanged;

    public bool IsSelected
    {
        get => _isSelected;
        set
        {
            if (_isSelected != value)
            {
                _isSelected = value;
                OnPropertyChanged(nameof(IsSelected));
            }
        }
    }

    public int Index
    {
        get => _index;
        set
        {
            if (_index != value)
            {
                _index = value;
                OnPropertyChanged(nameof(Index));
            }
        }
    }

    public string FunctionCode
    {
        get => _functionCode;
        set
        {
            if (_functionCode != value)
            {
                _functionCode = value;
                OnPropertyChanged(nameof(FunctionCode));
            }
        }
    }

    public string Device
    {
        get => _device;
        set
        {
            if (_device != value)
            {
                _device = value;
                OnPropertyChanged(nameof(Device));
            }
        }
    }

    public string Register
    {
        get => _register;
        set
        {
            if (_register != value)
            {
                _register = value;
                OnPropertyChanged(nameof(Register));
            }
        }
    }

    public string Value
    {
        get => _value;
        set
        {
            if (_value != value)
            {
                _value = value;
                OnPropertyChanged(nameof(Value));
            }
        }
    }

    public string Command
    {
        get => _command;
        set
        {
            if (_command != value)
            {
                _command = value;
                OnPropertyChanged(nameof(Command));
            }
        }
    }

    public string Description
    {
        get => _description;
        set
        {
            if (_description != value)
            {
                _description = value;
                OnPropertyChanged(nameof(Description));
            }
        }
    }

    public string Remark
    {
        get => _remark;
        set
        {
            if (_remark != value)
            {
                _remark = value;
                OnPropertyChanged(nameof(Remark));
            }
        }
    }

    protected virtual void OnPropertyChanged(string propertyName)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
